If ObjectProperty(Object_ID('dbo.opengiving_eventRegistrationInsert_sp'), N'IsProcedure') Is Null
Begin
    Execute ('Create Procedure dbo.opengiving_eventRegistrationInsert_sp As Print ''Hello World!''')
    RaisError('Procedure opengiving_eventRegistrationInsert_sp created.', 10, 1);
End;
Go

Set ANSI_Nulls On;
Set Quoted_Identifier On;
Go

Alter Procedure dbo.opengiving_eventRegistrationInsert_sp

        /* Declare Parameters */
              @event_id             int
            , @contact_id           int
            , @organization_id      smallint
            , @dateRegistered       smalldatetime
            , @dateUnregistered     smalldatetime   = Null
            , @attended             bit             = 0
            
As
/*********************************************************************************
    Name:       opengiving_eventRegistrationInsert_sp

    Author:     Michelle Ufford

    Purpose:    Inserts a record into the opengiving_eventRegistration table.

    Notes:      Part of the OpenGiving open-source project, 
                http://opengiving.codeplex.com

    Called by:  admin tool

    Date        User    Description
    ----------------------------------------------------------------------------
    2009-05-05  MFU     Initial Release
*********************************************************************************
    Exec dbo.opengiving_eventRegistrationInsert_sp
              @event_id         = 1
            , @contact_id       = 1
            , @organization_id  = 1
            , @dateRegistered   = '2009-01-01'
            , @dateUnregistered = NULL
            , @attended         = 1;
*********************************************************************************/

Set NoCount On;
Set XACT_Abort On;
Set Ansi_Padding On;
Set Ansi_Warnings On;
Set ArithAbort On;
Set Concat_Null_Yields_Null On;
Set Numeric_RoundAbort Off;

Begin
    Begin Try
   
        /* Start a new transaction */
        Begin Transaction;

        Insert Into dbo.opengiving_eventRegistration
        (
              event_id
            , contact_id
            , organization_id
            , dateRegistered
            , dateUnregistered
            , attended
        )
        Values
        (
              @event_id
            , @contact_id
            , @organization_id
            , @dateRegistered
            , @dateUnregistered
            , @attended
        );

        /* If you have an open transaction, commit it */
        If @@TranCount > 0
            Commit Transaction;

    End Try
    Begin Catch

        /* Whoops, there was an error... rollback! */
        If @@TranCount > 0
            Rollback Transaction;

        /* Return an error message and log it */
        Execute dbo.dba_logError_sp;

    End Catch;

    Set NoCount Off;
    Return 0;
End
Go

Set Quoted_Identifier Off;
Go